/**
 * 
 */
package anvil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author liutao
 * 
 */
public class RunStub {
	public void run(ArrayList<String> seeds, ArrayList<String> authcodes) {
		ExecutorService exec = Executors.newCachedThreadPool();
		@SuppressWarnings("unused")
		int partition = 0;// @Documented partion the code and seeds

		ArrayList<ArrayList<String>> seedslist = new ArrayList<ArrayList<String>>();
		seedslist = this.GetPartition(seeds, authcodes);
		// ArrayList<Future<Integer>> rs = new ArrayList<Future<Integer>>();
		for (int i = 0; i < authcodes.size(); i++) {
			exec.submit(new Splint(authcodes.get(i), Integer.toString(i),
					seedslist.get(i)));
		}

		return;
	}

	public ArrayList<ArrayList<String>> GetPartition(ArrayList<String> seeds,
			ArrayList<String> authcodes) {
		// TODO Auto-generated method stub
		ArrayList<ArrayList<String>> rs = new ArrayList<ArrayList<String>>();
		int p = seeds.size() / authcodes.size();
		Iterator<String> it = seeds.iterator();
		int c = 0;
		int i = 0;
		while (it.hasNext()) {

			rs.add(new ArrayList<String>());
			rs.get(i).add(it.next());
			c++;
			if (c == p && i + 1 < authcodes.size()) {
				i++;
				c = 0;
			}
		}
		return rs;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<String> s = new ArrayList<String>();
		s.add("a");
		s.add("b");
		s.add("c");
		s.add("d");
		s.add("e");
		s.add("f");
		s.add("g");

		ArrayList<String> t = new ArrayList<String>();
		t.add("c");
		t.add("c");
		t.add("c");
		RunStub st = new RunStub();
		@SuppressWarnings("unused")
		ArrayList<ArrayList<String>> rs = st.GetPartition(s, t);
		return;
	}

}
